package cn.echoedu.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import cn.echoedu.daoconstants.Databases;
import cn.echoedu.daoimpl.MySqlFactory;
import cn.echoedu.util.L;

public abstract class DAOFactory {

	public abstract DAOInsert getDAOInsert() throws SQLException;
	public abstract DAORead getDAORead() throws SQLException;
	public abstract DAODelete getDAODelete();
	public abstract DAOUpdate getDAOUpdate();
	public static DAOFactory factoryProducer(Databases db){
		switch (db){
		//	  case Oracle:
		//		  break;
		case MySql:
			return new MySqlFactory();
		default:
			return null;
		}
	}
	public static void closeAll(Connection conn,Statement ps,ResultSet rs){
		//		L.p("CloseDB"+ps.toString());
		//		try {
		//			if(conn != null){
		//				conn.close();
		//				conn = null;
		//			}
		//			L.p("Connection$@$@$@$@$@CLOSE SUCCESS");
		//		} catch (SQLException e) {
		//			// TODO Auto-generated catch block
		//			e.printStackTrace();
		//			L.p("Connection$@$@$@$@$@CLOSE Failure");
		//		}


		try {
			if(rs!=null){
				rs.close();
			}
			L.p("RSSULTSET$@$@$@$@$@CLOSE SUCCESS");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			L.p("STAMENT$@$@$@$@$@CLOSE FAILURE");
		}
		try{
			if(ps!=null){
				ps.close();
			}
			L.p("STAMENT$@$@$@$@$@CLOSE SUCCESS");
		}catch(Exception e){
			e.printStackTrace();
			L.p("STAMENT$@$@$@$@$@CLOSE FAILURE");
		}
		try {
			if(conn!=null){
				
				conn.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			L.p("CONNECTION$@$@$@$@$@CLOSE FAILURE");
		}


	}
}
